﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace WebManagerSystem1.Models
{
    public class CPublic
    {
        /// <summary>
        /// 系统标题
        /// </summary>
        public static string Title = "系统管理平台";
        /// <summary>
        /// 系统版本
        /// </summary>
        public static string Version = "V1.0";
        public static ConfigEx Config = new ConfigEx();
        internal static Models.DataContext dc = new DataContext();
        internal static BaseLibrary.ClassLibrary.EAFLog.Log log = new BaseLibrary.ClassLibrary.EAFLog.Log(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"), BaseLibrary.ClassLibrary.EAFLog.LogType.Daily);
        /// <summary>
        /// 得到web登录用户
        /// </summary>
        /// <returns></returns>
        public static BaseLibrary.Permissions.Tables.TUser GetLoginUser()
        {
            if (UserSession.UserID==0)
                throw new Exception("请先重新登录");
            var user = dc.TUser.ToTable().FirstOrDefault(c => c.UserID == UserSession.UserID);
            if (user == null)
                throw new Exception("请先重新登录");
            return user;
        }
        /// <summary>
        /// 得到web登录用户所有用户组
        /// </summary>
        /// <returns></returns>
        public static BaseLibrary.Permissions.Tables.TUserGroup[] GetLoginUserGroup()
        {
            return dc.GetUserGroup(UserSession.UserID).ToArray();
        }
    }
}
